<?php

namespace App\Service\Moment;

use App\Constants\ErrorCode;
use App\Model\CommentLike;
use App\Model\MomentComment;
use App\Service\BaseService;

/**
 * 动态评论点赞
 */
class MomentCommentLikeService extends BaseService
{
    public function handle()
    {
        $option = $this->request->input('option', 1);
        $commentId = $this->request->input('comment_id', 0);
        $momentId = $this->request->input('moment_id', 0);
        if (!$commentId) return $this->setError(ErrorCode::PARAMETER_ERROR);
        //添加喜欢记录
        $result = CommentLike::addLike($this->getUserId(), $commentId, $option, $momentId);
        //动态表修改
        if ($result) MomentComment::updateLikeNum($commentId, $option == 1 ? 1 : -1);
        $ret = [
            'result' => $result,
        ];
        return $ret;
    }
}
